<?php $this->pageTitle = 'Add New User'; ?>
<div class="main-title no-border">
    <h1 class="float-left">Add user</h1>
</div>
<div class="grid_16">
	<?php
	$form = $this->beginWidget('PsActiveForm', array(
		'action' => Yii::app()->createUrl($this->route),
	));
	?>
	<div class="form">
		<div class="section">
			<div class="block">
				<h2>User Details</h2>
				<table class="form-table">
					<tr>
						<th scope="row" class="align-right" width="100">
							<?php echo $form->labelEx($user, 'license_no', array('label' => 'CEA License No.')); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'license_no'); ?>
							<button id="btnSearchCEADatabase" type="button" class="link-button">Search CEA Database</button>
							<?php echo $form->error($user, 'license_no'); ?>
						</td>
					</tr>
					<tr>
						<th scope="row" class="align-right" width="100">
							<?php echo $form->labelEx($user, 'username'); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'username', array('autocomplete' => 'off')); ?>
							<?php echo $form->error($user, 'username'); ?>
						</td>
					</tr>
					<tr>
						<th scope="row" class="align-right">
							<?php echo $form->labelEx($user, 'name'); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'name', array('size' => 50, 'maxlength' => 255, 'autocomplete' => 'off')); ?>
							<?php echo $form->error($user, 'name'); ?>
						</td>
					</tr>
					<tr>
						<th scope="row" class="align-right">
							<?php echo $form->labelEx($user, 'nric', array('label' => 'NRIC')); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'nric', array('size' => 20, 'maxlength' => 30, 'autocomplete' => 'off')); ?>
							<?php echo $form->error($user, 'nric'); ?>
						</td>
					</tr>	
					<?php if (Yii::app()->user->hasMultipleAgenciesSelected()): ?>
						<tr>
							<th scope="row" class="align-right">
								<?php echo $form->labelEx($user, 'agency_id'); ?>
							</th>
							<td>
								<?php
								$this->widget('common.widgets.PsSelect2.PsSelect2', array(
									'model' => $user,
									'attribute' => 'agency_id',
									'data' => $this->getAgencyListData(),
									'htmlOptions' => array(
										'prompt' => 'Select Agency',
										'multiple' => false,
										'style' => 'width:350px;',
									)
								));
								?>
								<?php echo $form->error($user, 'agency_id'); ?>
							</td>
						</tr>
					<?php endif; ?>					
					<?php if (Yii::app()->user->checkModuleAccess('Propsage.Vendor')): ?>
						<tr>
							<th scope="row" class="align-right">
								<?php echo $form->labelEx($user, 'vendor_id', array('label' => 'Vendor')); ?>
							</th>
							<td>
								<?php
								$this->widget('common.widgets.PsSelect2.PsSelect2', array(
									'model' => $user,
									'attribute' => 'vendor_id',
									'data' => Yii::app()->user->model->agency->getVendorsListData(),
									'htmlOptions' => array(
										'prompt' => '',
										'multiple' => false,
										'style' => 'width:300px;',
										'data-placeholder' => 'Select vendor'
									)
								));
								?>
								<?php echo $form->error($user, 'vendor_id'); ?>
								<p class="hint">Select this if this user is a vendor account. For normal salespersons & agency accounts, leave this option blank.</p>
							</td>
						</tr>
					<?php endif; ?>	
				</table>
				<h3>Password</h3>
				<table class="form-table">
					<tr>
						<th scope="row" class="align-right" width="100">
							<label><?php echo $form->labelEx($user, 'password'); ?></label>
						</th>
						<td>
							<?php echo $form->textField($user, 'password', array('autocomplete' => 'off')); ?>
							<button id="btnRandomPassword" type="button" class="link-button">Randomize</button>
							<?php echo $form->error($user, 'password'); ?>
						</td>
					</tr>
					<tr>
						<th scope="row" class="align-right" width="100"></th>
						<td>
							<input id="sendEmail" type="checkbox" name="sendEmail" value="1" checked />
							<label for="sendEmail">Send password to user via Email</label>            
							<br/>
							<input id="sendSMS" type="checkbox" name="sendSMS" value="1" checked />
							<label for="sendSMS">Send password to user via SMS</label>        
						</td>
					</tr>
				</table>
				<h3>Contact Information</h3>
				<table class="form-table">										
					<tr>
						<th scope="row" class="align-right" width="100">
							<?php echo $form->labelEx($user, 'email'); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'email', array('size' => 50, 'maxlength' => 50, 'autocomplete' => 'off')); ?>
							<?php echo $form->error($user, 'email'); ?>
						</td>
					</tr>
					<tr>
						<th scope="row" class="align-right">
							<?php echo $form->labelEx($user, 'mobile'); ?>
						</th>
						<td>
							<?php echo $form->textField($user, 'mobile', array('size' => 20, 'maxlength' => 30, 'autocomplete' => 'off')); ?>
							<?php echo $form->error($user, 'mobile'); ?>
						</td>
					</tr>
				</table>
				<h3>Roles</h3>
				<div class="">
					<?php
					echo $form->checkBoxList($user, 'userAuthItems', UserAuthItem::getRolesListData($user->agency_id), array(
						'labelOptions' => array(
							'style' => 'text-align: left;'
						)
					));
					?>
				</div>
			</div>
		</div>
		<div class="form-buttons row">
			<input type="submit" value="Add User" class="green link-button" />
		</div>
	</div>
	<?php $this->endWidget(); ?>
</div>